﻿@Messages =

    WriteErrors: (textErrors) ->
        if textErrors? && textErrors.length
            Messages.Clear()
            _.each(textErrors, (error) -> 
                if error.Key? && error.Key.length > 0
                    div = $("body").find("form").find("input[name=#{ error.Key }], textarea[name=#{ error.Key }], select[name=#{ error.Key }]").closest("fieldset > div")
                    if div.length
                        div.data("error-message", error.Message)
                        div.addClass("error")
                else
                    alertify.error(error.Message)
            )

    WriteSuccessMessage: (textmessage) ->
        alertify.success(textmessage)

    WriteMessage: (textmessage) ->
        alertify.log(textmessage)           

    Clear: ->
        $("#alertify-logs").find("article").remove()